package com.cy.util;

public class RedisKeyUtil {

    private static final String SPLIT = ":";
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PREFIX_USER_LIKE = "like:user";  //我收到的赞key

    //A关注了B，则A是B的Follower(关注者)，B是A的Followee（被关注者）
    private static final String PREFIX_FOLLOWEE = "followee";   //被关注者
    private static final String PREFIX_FOLLOWER = "follower";   //关注者

    //验证码
    private static final String PREFIX_KAPTCHA = "kaptcha";

    //登录凭证
    private static final  String PREFIX_TICKET = "ticket";

    private static final String PREFIX_USER = "user";

    public static final String PREFIX_UV = "uv";

    public static final String PREFIX_DAU = "dau";

    public static final String PREFIX_POST = "post";

    // 某个实体的赞帖子或者评论  将对其点赞的用户id存入set中
    // like:entity:entityType:entityId -> set(userId)
    // 这里的entityType分为贴子和评论   entityType为1代表帖子   entityType为2代表评论点赞
    public static String getEntityLikeKey(int entityType, int entityId) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    // 某个用户的赞
    // like:user:userId -> int
    public static String getUserLikeKey(int userId) {
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    // 某个用户关注的实体
    // followee:userId:entityType -> zset(entityId,now)
    public static String  getFolloweeKey(int entityType, int userId){
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType ;
    }

    // 某个实体拥有的粉丝
    // follower:entityType:entityId -> zset(userId,now)
    public static String getFollowerKey(int entityType, int entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }


    /**
     * 验证码
     * @param owner    登录凭证
     * @return
     */
    //kaptcha:登录凭证
    public static String getKaptchaKey(String owner){
        return PREFIX_KAPTCHA + SPLIT + owner;
    }


    // 登录凭证
    public static String getTicketKey(String ticket){
        return PREFIX_TICKET + SPLIT + ticket;
    }


    // 用户
    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

    // 单日UV
    public static String getUVKey(String date){
        return PREFIX_UV + SPLIT + date;
    }

    // 区间UV
    public static String getUVKey(String startDate, String endDate){
        return PREFIX_UV + SPLIT + startDate + SPLIT + endDate;
    }

    // DAU单日活跃用户
    public static String getDAUKey(String date){
        return PREFIX_DAU + SPLIT + date;
    }
    // DAU区间活跃用户
    public static String getDAUKey(String startDate, String endDate){
        return PREFIX_DAU + SPLIT + startDate + SPLIT + endDate;

    }


    // 帖子分数
    public static String getPostScoreKey(){
        return PREFIX_POST + SPLIT + "score";
    }

}
